package br.com.translog.gui.fornecimento;

import br.com.translog.gui.funcionario.*;
import br.com.translog.fachada.FachadaTranslog;
import br.com.translog.gui.outro.FrmMenuPrincipal;
import br.com.translog.modelo.Fornecimento;
import br.com.translog.modelo.FornecimentoPK;
import br.com.translog.modelo.Funcionario;
import br.com.translog.modelo.Logradouro;
import br.com.translog.modelo.PessoaFisica;
import java.text.SimpleDateFormat;
import java.util.Date;

public class FrmFornecimentoCadastrar extends javax.swing.JFrame {

    /**
     * Creates new form FrmFuncionarioCadastrar
     */
    public FrmFornecimentoCadastrar() {
        initComponents();
        setLocationRelativeTo(null);
    }

    /**
     * This method is called from within the constructor to initialize the form. WARNING: Do NOT
     * modify this code. The content of this method is always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlFuncionarioCadastrar = new javax.swing.JPanel();
        txtMatricula1 = new javax.swing.JTextField();
        txtMatricula3 = new javax.swing.JTextField();
        lblAlterarFuncionario = new javax.swing.JLabel();
        lblMatricula = new javax.swing.JLabel();
        lblFuncionario = new javax.swing.JLabel();
        btnAtualizar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        lblFuncionario2 = new javax.swing.JLabel();
        txtMatricula = new javax.swing.JTextField();
        lblFuncionario3 = new javax.swing.JLabel();
        txtMatricula4 = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("TransLog - Sistema de Entrega de Transportadora - Cadastro de Funcionário");
        setMaximumSize(null);
        setMinimumSize(null);
        setName("frmFuncionarioCadastrar"); // NOI18N
        setPreferredSize(null);
        setResizable(false);

        pnlFuncionarioCadastrar.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        pnlFuncionarioCadastrar.setMaximumSize(new java.awt.Dimension(970, 316));
        pnlFuncionarioCadastrar.setMinimumSize(new java.awt.Dimension(970, 316));

        lblAlterarFuncionario.setFont(new java.awt.Font("Tahoma", 1, 15)); // NOI18N
        lblAlterarFuncionario.setText("CADASTRAR FORNECIMENTO");
        lblAlterarFuncionario.setName(""); // NOI18N

        lblMatricula.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblMatricula.setText("Data de Fornecimento");

        lblFuncionario.setText("Quantidade");

        btnAtualizar.setText("Cadastrar");
        btnAtualizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAtualizarActionPerformed(evt);
            }
        });

        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        lblFuncionario2.setText("Cod. Fornecedor");

        lblFuncionario3.setText("Cod. Produto");

        javax.swing.GroupLayout pnlFuncionarioCadastrarLayout = new javax.swing.GroupLayout(pnlFuncionarioCadastrar);
        pnlFuncionarioCadastrar.setLayout(pnlFuncionarioCadastrarLayout);
        pnlFuncionarioCadastrarLayout.setHorizontalGroup(
            pnlFuncionarioCadastrarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlFuncionarioCadastrarLayout.createSequentialGroup()
                .addGroup(pnlFuncionarioCadastrarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlFuncionarioCadastrarLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(pnlFuncionarioCadastrarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pnlFuncionarioCadastrarLayout.createSequentialGroup()
                                .addGroup(pnlFuncionarioCadastrarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lblFuncionario2)
                                    .addComponent(lblFuncionario3))
                                .addGap(59, 59, 59)
                                .addGroup(pnlFuncionarioCadastrarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(txtMatricula1, javax.swing.GroupLayout.DEFAULT_SIZE, 106, Short.MAX_VALUE)
                                    .addComponent(txtMatricula4)))
                            .addGroup(pnlFuncionarioCadastrarLayout.createSequentialGroup()
                                .addGroup(pnlFuncionarioCadastrarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(pnlFuncionarioCadastrarLayout.createSequentialGroup()
                                        .addComponent(btnAtualizar, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(45, 45, 45)
                                        .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(pnlFuncionarioCadastrarLayout.createSequentialGroup()
                                        .addComponent(lblMatricula)
                                        .addGap(18, 18, 18)
                                        .addComponent(txtMatricula, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(79, 79, 79)
                                        .addComponent(lblFuncionario)))
                                .addGap(18, 18, 18)
                                .addComponent(txtMatricula3, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(pnlFuncionarioCadastrarLayout.createSequentialGroup()
                        .addGap(187, 187, 187)
                        .addComponent(lblAlterarFuncionario)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pnlFuncionarioCadastrarLayout.setVerticalGroup(
            pnlFuncionarioCadastrarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlFuncionarioCadastrarLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblAlterarFuncionario)
                .addGap(18, 18, 18)
                .addGroup(pnlFuncionarioCadastrarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblMatricula)
                    .addComponent(txtMatricula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblFuncionario)
                    .addComponent(txtMatricula3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(pnlFuncionarioCadastrarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblFuncionario2)
                    .addComponent(txtMatricula1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlFuncionarioCadastrarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblFuncionario3)
                    .addComponent(txtMatricula4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(pnlFuncionarioCadastrarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAtualizar)
                    .addComponent(btnCancelar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pnlFuncionarioCadastrar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pnlFuncionarioCadastrar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnAtualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAtualizarActionPerformed

        //Instanciando os objetos que serao utilizados...
        Fornecimento f = new Fornecimento();
        
        Date data;
        
        try {
            //Convertendo as datas para o tipo "Date"...
            data = new SimpleDateFormat("dd/MM/yyyy").parse(txtMatricula.getText());
            
            f.setData(data);   
            FornecimentoPK fornecimentoPK = new FornecimentoPK(Integer.parseInt(txtMatricula1.getText()), Integer.parseInt(txtMatricula4.getText()));
            f.setFornecimentoPK(fornecimentoPK);
            f.setFornecedor(FachadaTranslog.getInstFachadaTranslog().consultaFornecedor(Integer.parseInt(txtMatricula1.getText())));
            f.setProduto(FachadaTranslog.getInstFachadaTranslog().consultaProduto(Integer.parseInt(txtMatricula4.getText())));
            f.setQuantidade(Integer.parseInt(txtMatricula3.getText()));
            
            
            //Passando os objetos para serem persistidos...
            //FachadaTranslog.getInstFachadaTranslog().cadastraFornecimento(f);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_btnAtualizarActionPerformed

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed

        new FrmMenuPrincipal().setVisible(true);
        this.dispose();
    }//GEN-LAST:event_btnCancelarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FrmFuncionarioCadastrar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FrmFuncionarioCadastrar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FrmFuncionarioCadastrar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FrmFuncionarioCadastrar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new FrmFuncionarioCadastrar().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAtualizar;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JLabel lblAlterarFuncionario;
    private javax.swing.JLabel lblFuncionario;
    private javax.swing.JLabel lblFuncionario2;
    private javax.swing.JLabel lblFuncionario3;
    private javax.swing.JLabel lblMatricula;
    private javax.swing.JPanel pnlFuncionarioCadastrar;
    private javax.swing.JTextField txtMatricula;
    private javax.swing.JTextField txtMatricula1;
    private javax.swing.JTextField txtMatricula3;
    private javax.swing.JTextField txtMatricula4;
    // End of variables declaration//GEN-END:variables
}
